<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>字典管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/libs/layui2.2.5/css/layui.css">
    <link rel="icon" href="href="${pageContext.request.contextPath}/static/libs/uiframe/frame/static/image/code.png">
    <style type="text/css">
        .layui-table-cell .layui-form-checkbox {
            top: 6px;
        }
    </style>
</head>
<body class="body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>字典列表</legend>
</fieldset>
<div style="margin-left: 10px;">
    <button class="layui-btn layui-btn-xs layui-btn-normal" id="add_btn"><i class="layui-icon"></i>新增</button>
    <button class="layui-btn layui-btn-xs layui-btn-normal" id="edit_btn"><i class="layui-icon"></i>编辑</button>
    <button class="layui-btn layui-btn-xs layui-btn-danger" id="remove_btn"><i class="layui-icon"></i>删除</button>
</div>
<table id="dictlist" class="layui-table" lay-filter=="dictlist"></table>
<script type="text/html" id="dictbar">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="dict_edit">查看详情</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="dict_delete">删除应用</a>
</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/libs/layui2.2.5/layui.js"></script>
<script type="text/javascript">
    var layIndex = null,tableIns;
    /**
     * 关闭弹窗，同时刷新数据列表
     * @param layIndex
     */
    function closeAllLayer() {
        layui.use(['table','layer'], function(){
            var $ = layui.jquery, layer = layui.layer;
            layer.closeAll();
            layIndex = null;
            tableIns.reload();
        });
    }

    /**
     * 列表初始化
     */
    layui.use(['table','layer'], function(){
        var table = layui.table,
            layer = layui.layer,
            $ = layui.jquery;

        tableIns = table.render({
            id: 'dictlist'
            ,elem: '#dictlist'
            ,height: 'full-140'
            ,url:'${pageContext.request.contextPath}/sys/dict/dictlist'
            ,cols: [[
                {checkbox: true, LAY_CHECKED: false} //默认全选
                ,{field: 'value',align:'center', title: '键值', width: 180}
                ,{field: 'label',align:'center', title: '标签', width: 180}
                ,{field: 'type', title: '类型', width: 180}
                ,{field: 'sort', title: '排序', width: 180}
                ,{field: 'description', title: '描述', width: 200}
                ,{fixed: 'right', align:'center',title: '操作', width: 240, toolbar: '#sourcebar'}
            ]]
            ,page: true
            ,limits: [10, 20, 30]
            ,limit: 10
        });

        /**
         * 新建按钮绑定事件
         */
        $("#add_btn").click(function () {
            if(layIndex != null) return;
            layIndex = layer.open({
                type: 2,
                title:'数据源添加',
                offset: 't',
                area: ['550px', '350px'],
                shade: 0,
                shadeClose:false,
                resize:true,
                content: '${pageContext.request.contextPath}/ol/sourceadd',
                cancel: function(index, layero){
                    layIndex = null;
                    layer.close(index);
                }
            });
        });
        /**
         * 编辑按钮绑定事件
         */
        $("#edit_btn").click(function () {
            if(layIndex != null) return;
            var checkStatus = table.checkStatus('rolelist'),roleid;
            if(checkStatus.data.length != 1){
                layer.msg('一次编辑只能选择一行', {icon: 5,anim: 6});
                return;
            }
            roleid = checkStatus.data[0]['id'];
            layIndex = layer.open({
                type: 2,
                title:'角色编辑',
                area: ['450px', '300px'],
                shade: 0,
                shadeClose:false,
                resize:true,
                content: ['${pageContext.request.contextPath}/sys/user/roleedit?roleid='+roleid, 'no'],
                cancel: function(index, layero){
                    layIndex = null;
                    layer.close(index);
                }
            });
        });

        /**
         * 删除按钮绑定事件
         */
        $("#remove_btn").click(function () {
            var checkStatus = table.checkStatus('sourcelist'),sourceids=[];
            if(checkStatus.data.length == 0){
                layer.msg('至少选择一行', {icon: 5,anim: 6});
                return;
            }
            for(var i = 0,len = checkStatus.data.length;i < len;i++){
                sourceids.push(checkStatus.data[i]['sourceId']);
            }

            $.ajax({
                type:'post',
                dataType:'json',
                url:'${pageContext.request.contextPath}/ol/sourceremove',
                contentType : "application/json;charset=UTF-8",
                data:sourceids.join(","),
                success:function (data) {
                    layer.msg(data.status);
                    closeAllLayer();
                },
                error:function (error) {
                    console.log(error);
                }
            });
        });
    });
</script>
</body>
</html>

